/**
 * 3
 *  
 * @Author : roryrywang
 * @DateTime : 24-8-28 下午6:59
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int diff = 0;
    int j = 0;
    int res = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '(') diff++;
        else diff--;

        if (diff == 0) {
            res = max(res, i - j + 1);
        } else if (diff < 0) {
            break;
        }
    }
    cout << res;
    return 0;
}
